//
//  PPAlbumShareView.m
//  pickpic
//
//  Created by Jinxiao on 10/1/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPAlbumShareView.h"

#import "PPAccountProfiles.h"

@interface PPAlbumShareView ()
@property (readwrite, nonatomic, strong) UIVisualEffectView *backgroundView;
@property (strong, nonatomic) IBOutlet UIView *contentView;

@property (strong, nonatomic) IBOutlet UIImageView *coverView;
@property (strong, nonatomic) IBOutlet UIImageView *avatarView;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UILabel *accountLabel;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UIImageView *backgroundImageView;

@end

@implementation PPAlbumShareView

- (void)awakeFromNib {
    [super awakeFromNib];

    _contentView.clipsToBounds = NO;

    _contentView.layer.shadowOffset = CGSizeMake(0, 2);
    _contentView.layer.shadowRadius = 4;
    _contentView.layer.shadowColor = [UIColor colorWithRGBHex:0x000000 alpha:1].CGColor;
    _contentView.layer.shadowOpacity = 1;

    _backgroundView = [[UIVisualEffectView alloc] init];
    _backgroundView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    [self insertSubview:_backgroundView aboveSubview:_backgroundImageView];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    _backgroundView.frame = self.bounds;
}

- (void)setCover:(UIImage *)cover {
    _cover = cover;

    _coverView.image = cover;

    _backgroundImageView.image = cover;
}

- (void)setAvatarURLString:(NSString *)avatarURLString {
    _avatarURLString = avatarURLString;

    if(_avatarURLString.length > 0) {
        [_avatarURLString applyToImageView:_avatarView];
    } else {
        _avatarView.image = [UIImage imageNamed:@"icon-person-70"];
    }
}

- (void)setName:(NSString *)name {
    _name = name;

    _nameLabel.text = _name;
}

- (void)setAccount:(NSString *)account {
    _account = account;

    _accountLabel.text = _account;
}

- (void)setTitle:(NSString *)title {
    _title = title;

    if(title == nil) {
        title = @"";
    }

    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
    paragraph.minimumLineHeight = 33;
    paragraph.maximumLineHeight = 33;
    paragraph.alignment = NSTextAlignmentCenter;
    paragraph.lineBreakMode = NSLineBreakByWordWrapping;

    _titleLabel.attributedText = [[NSAttributedString alloc] initWithString:title attributes:@{NSParagraphStyleAttributeName : paragraph, NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : [UIFont boldSystemFontOfSize:24]}];
}

@end
